<?php
    require_once 'Zend/Db.php';
    require_once 'Zend/Auth.php';
    require_once 'Zend/Auth/Adapter/DbTable.php';
    $db = Zend_Db::factory('Pdo_Mysql', array(
        'host'     => 'localhost',
        'username' => 'root',
        'password' => '',
        'dbname'   => 'tournow'
    ));
        
    $email = $_POST['email'];
    $password = $_POST['password'];
    $rememberMe = $_POST['rememberMe'];
    $msg = '';
    $auth = Zend_Auth::getInstance();
    $authAdapter = new Zend_Auth_Adapter_DbTable($db);
    $authAdapter->setTableName('user')
                ->setIdentityColumn('email')
                ->setCredentialColumn('password');
    $authAdapter->setIdentity($email);
    $authAdapter->setCredential(md5($password));
    $select = $authAdapter->getDbSelect();
    $select->where('status = 1');
    $result = $auth->authenticate($authAdapter);
    if($result->isValid())
    {
        $data = $authAdapter->getResultRowObject();
        $auth->getStorage()->write($data);
        if($rememberMe == '1')
        {
            $expires = time() + 60 * 60 * 24 * 365;
            setcookie('emailUser', $data->email, $expires);
            setcookie('passwordUser', $data->password, $expires);
        }
        $msg .='a';
    }
    else
    {
        $msg = '';
    }
    echo $msg;
